package com.kexilo.core.common.config.properties;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * 监控配置属性
 *
 * @author Kexilo
 */
@Component
@ConfigurationProperties(prefix = "kexilo.monitor")
public class MonitorProperties {
    
    private MetricsProperties metrics = new MetricsProperties();
    private TracingProperties tracing = new TracingProperties();
    private HealthProperties health = new HealthProperties();
    private AlertProperties alert = new AlertProperties();
    
    /**
     * 指标配置
     */
    public static class MetricsProperties {
        /** 是否启用指标收集 */
        private boolean enabled = true;
        
        /** 指标收集间隔（秒） */
        private int collectInterval = 30;
        
        /** 是否启用JVM指标 */
        private boolean enableJvmMetrics = true;
        
        /** 是否启用业务指标 */
        private boolean enableBusinessMetrics = true;
        
        /** 指标保留时间（小时） */
        private int retentionHours = 72;

        // Getter and Setter methods
        public boolean isEnabled() {
            return enabled;
        }

        public void setEnabled(boolean enabled) {
            this.enabled = enabled;
        }

        public int getCollectInterval() {
            return collectInterval;
        }

        public void setCollectInterval(int collectInterval) {
            this.collectInterval = collectInterval;
        }

        public boolean isEnableJvmMetrics() {
            return enableJvmMetrics;
        }

        public void setEnableJvmMetrics(boolean enableJvmMetrics) {
            this.enableJvmMetrics = enableJvmMetrics;
        }

        public boolean isEnableBusinessMetrics() {
            return enableBusinessMetrics;
        }

        public void setEnableBusinessMetrics(boolean enableBusinessMetrics) {
            this.enableBusinessMetrics = enableBusinessMetrics;
        }

        public int getRetentionHours() {
            return retentionHours;
        }

        public void setRetentionHours(int retentionHours) {
            this.retentionHours = retentionHours;
        }
    }
    
    /**
     * 链路追踪配置
     */
    public static class TracingProperties {
        /** 是否启用链路追踪 */
        private boolean enabled = false;
        
        /** 采样率 */
        private double samplingRate = 0.1;
        
        /** 追踪服务名 */
        private String serviceName = "kexilo-backend";
        
        /** Jaeger端点 */
        private String jaegerEndpoint = "http://localhost:14268/api/traces";

        // Getter and Setter methods
        public boolean isEnabled() {
            return enabled;
        }

        public void setEnabled(boolean enabled) {
            this.enabled = enabled;
        }

        public double getSamplingRate() {
            return samplingRate;
        }

        public void setSamplingRate(double samplingRate) {
            this.samplingRate = samplingRate;
        }

        public String getServiceName() {
            return serviceName;
        }

        public void setServiceName(String serviceName) {
            this.serviceName = serviceName;
        }

        public String getJaegerEndpoint() {
            return jaegerEndpoint;
        }

        public void setJaegerEndpoint(String jaegerEndpoint) {
            this.jaegerEndpoint = jaegerEndpoint;
        }
    }
    
    /**
     * 健康检查配置
     */
    public static class HealthProperties {
        /** 是否启用自定义健康检查 */
        private boolean enableCustomChecks = true;
        
        /** 数据库连接超时时间（秒） */
        private int dbTimeout = 5;
        
        /** Redis连接超时时间（秒） */
        private int redisTimeout = 3;
        
        /** 磁盘空间阈值（百分比） */
        private int diskSpaceThreshold = 85;

        // Getter and Setter methods
        public boolean isEnableCustomChecks() {
            return enableCustomChecks;
        }

        public void setEnableCustomChecks(boolean enableCustomChecks) {
            this.enableCustomChecks = enableCustomChecks;
        }

        public int getDbTimeout() {
            return dbTimeout;
        }

        public void setDbTimeout(int dbTimeout) {
            this.dbTimeout = dbTimeout;
        }

        public int getRedisTimeout() {
            return redisTimeout;
        }

        public void setRedisTimeout(int redisTimeout) {
            this.redisTimeout = redisTimeout;
        }

        public int getDiskSpaceThreshold() {
            return diskSpaceThreshold;
        }

        public void setDiskSpaceThreshold(int diskSpaceThreshold) {
            this.diskSpaceThreshold = diskSpaceThreshold;
        }
    }
    
    /**
     * 告警配置
     */
    public static class AlertProperties {
        /** 是否启用告警 */
        private boolean enabled = false;
        
        /** CPU使用率告警阈值（百分比） */
        private int cpuThreshold = 80;
        
        /** 内存使用率告警阈值（百分比） */
        private int memoryThreshold = 85;
        
        /** 错误率告警阈值（百分比） */
        private int errorRateThreshold = 5;
        
        /** 告警通知邮箱 */
        private String[] notificationEmails = {};

        // Getter and Setter methods
        public boolean isEnabled() {
            return enabled;
        }

        public void setEnabled(boolean enabled) {
            this.enabled = enabled;
        }

        public int getCpuThreshold() {
            return cpuThreshold;
        }

        public void setCpuThreshold(int cpuThreshold) {
            this.cpuThreshold = cpuThreshold;
        }

        public int getMemoryThreshold() {
            return memoryThreshold;
        }

        public void setMemoryThreshold(int memoryThreshold) {
            this.memoryThreshold = memoryThreshold;
        }

        public int getErrorRateThreshold() {
            return errorRateThreshold;
        }

        public void setErrorRateThreshold(int errorRateThreshold) {
            this.errorRateThreshold = errorRateThreshold;
        }

        public String[] getNotificationEmails() {
            return notificationEmails;
        }

        public void setNotificationEmails(String[] notificationEmails) {
            this.notificationEmails = notificationEmails;
        }
    }

    // Main class getter and setter methods
    public MetricsProperties getMetrics() {
        return metrics;
    }

    public void setMetrics(MetricsProperties metrics) {
        this.metrics = metrics;
    }

    public TracingProperties getTracing() {
        return tracing;
    }

    public void setTracing(TracingProperties tracing) {
        this.tracing = tracing;
    }

    public HealthProperties getHealth() {
        return health;
    }

    public void setHealth(HealthProperties health) {
        this.health = health;
    }

    public AlertProperties getAlert() {
        return alert;
    }

    public void setAlert(AlertProperties alert) {
        this.alert = alert;
    }
}
